<template>
  <div>
    <h4>当前是项目管理-- 项目基本信息 project</h4>
    <el-form :inline="true">
      <el-form-item>
        <!-- <el-input
						v-model="searchForm.username"
						placeholder="用户名"
						clearable
				>
				</el-input> -->
        <el-input
          v-model="projectname"
          placeholder="请输入项目名称..."
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="projectphone"
          placeholder="请输入项目客服电话..."
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button @click="getProject">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="dialogVisible = true">新增</el-button>
      </el-form-item>
      <!-- <el-form-item>
				<el-button type="primary" @click="dialogVisible = true" v-if="hasAuth('sys:user:save')">新增</el-button>
			</el-form-item>
			<el-form-item>
				<el-popconfirm title="这是确定批量删除吗？" @confirm="delHandle(null)">
					<el-button type="danger" slot="reference" :disabled="delBtlStatu" v-if="hasAuth('sys:user:delete')">批量删除</el-button>
				</el-popconfirm>
			</el-form-item> -->
    </el-form>
    <!--新增对话框-->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="600px"
      :before-close="handleClose"
    >
      <el-form :model="editForm" :rules="editFormRules" ref="editForm">
        <el-form-item label="项目名称：" prop="projectName" label-width="100px">
          <el-input
            v-model="editForm.projectName"
            autocomplete="off"
          ></el-input>
          <el-alert
            title="公司名称缩写加上项目地址缩写"
            :closable="false"
            type="info"
            style="line-height: 12px"
          ></el-alert>
        </el-form-item>

        <el-form-item label="联系电话：" prop="phone1" label-width="100px">
          <el-input v-model="editForm.phone1" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="客服电话：" prop="phone2" label-width="100px">
          <el-input v-model="editForm.phone2" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          label="项目地址："
          prop="projectAddress"
          label-width="100px"
        >
          <el-input
            v-model="editForm.projectAddress"
            autocomplete="off"
          ></el-input>
          <el-alert
            title="填写项目地址方方便后期进行一个项目维护"
            :closable="false"
            type="info"
            style="line-height: 12px"
          ></el-alert>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm('editForm')">取 消</el-button>
        <el-button type="primary" @click="submitForm('editForm')"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="projectName" label="项目名称"> </el-table-column>
      <el-table-column prop="phone1" label="联系电话"> </el-table-column>
      <el-table-column prop="phone2" label="客服电话"> </el-table-column>
      <el-table-column prop="projectAddress" label="项目地址">
      </el-table-column>
      <el-table-column prop="created" label="创建日期"> </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >编辑项目</el-button
          >
          <el-button type="text" @click="handleDelete(scope.row)" size="small"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="current"
      :page-sizes="[1, 10, 15, 20, 30]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "Project",

  data() {
    return {
      ///  新增项目信息的模块隐藏
      dialogVisible: false,
      currentPage4: 4,
      projectphone: "",
      projectname: "",
      total: 0,
      size: 1,
      current: 1,
      tableData: [],
      editForm: {},
      editFormRules: {
        projectName: [
          { required: true, message: "请输入用户名称", trigger: "blur" },
        ],
        phone1: [
          { required: true, message: "请输入联系电话", trigger: "blur" },
        ],
        phone2: [
          { required: true, message: "请输入客服电话", trigger: "blur" },
        ],
        projectAddress: [
          { required: true, message: "请填写项目地址", trigger: "blur" },
        ],
      },
    };
  },
  //  页面加载前调用的方法
  created() {
    this.getProject();
  },
  methods: {
    // c查看按钮
    handleClick(row) {
      console.log(row);
      (this.dialogVisible = true),
        (this.editForm = {
          projectName: row.projectName,
          phone1: row.phone1,
          phone2: row.phone2,
          projectAddress: row.projectAddress,
          projectid: row.projectid,
        });
    },
    handleSizeChange(val) {
      console.log(`每页条` + val);
      this.size = val;
      this.getProject();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ` + val);
      this.current = val;
      this.getProject();
    },
    // 搜索按钮
    // getUserList(){
    //   alert("ok")
    // },
    //  查询项目信息
    getProject() {
      this.$axios
        .get("/tProjectBase/list", {
          params: {
            projectname: this.projectname,
            projectphone: this.projectphone,
            current: this.current,
            size: this.size,
          },
        })
        .then((res) => {
          console.log(res);
          this.tableData = res.data.data.records;
          this.size = res.data.data.size;
          this.current = res.data.data.current;
          this.total = res.data.data.total;
        });
    },
    // 用户信息编辑的一个取消
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dialogVisible = false;
      this.editForm = {};
    },
    // 关闭用户信息框
    handleClose() {
      this.resetForm("editForm");
    },
    /// 用户信息框的用户信息提交按钮
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(formName);
          console.log(valid);
          console.log(this.editForm);
          alert("表单验证成功！！！");
          this.$axios
            .post(
              "/tProjectBase/" + (this.editForm.projectid ? "updata" : "add"),
              this.editForm
            )
            .then((res) => {
              if (res) {
                this.$message({
                  showClose: true,
                  message: "恭喜你，项目操作成功",
                  type: "success",
                  onClose: () => {
                    this.dialogVisible = false;
                    this.getProject();
                  },
                });

                //alert('success')
              } else {
                alert("err");
              }
            });
        } else {
          console.log("error submit!!");
          alert("表单验证失败！！！");
          return false;
        }
      });
    },
    /// 删除项目信息
    handleDelete(rows) {
      this.$confirm(
        "你确定需要删除“" + rows.projectName + "”项目信息吗？？",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        this.$axios
          .post("/tProjectBase/delete", rows.projectid)
          .then((res) => {
            this.$message({
              showClose: true,
              message: "恭喜你，删除成功",
              type: "success",
              onClose: () => {
                this.getProject();
              },
            });
          });
      });
    },
  },
};
</script>

<style scoped>
.el-pagination {
  float: right;
  margin-top: 22px;
}
</style>